import axios from 'axios';

const apiClient = axios.create({
    timeout: 10000,
});

// --- Strategy Endpoints ---

export const createStrategy = (strategyData) => {
    return apiClient.post('/api/strategies', strategyData);
};

export const getAllStrategies = () => {
    return apiClient.get('/api/strategies');
};

export const getStrategyById = (id) => {
    return apiClient.get(`/api/strategies/${id}`);
};

export const updateStrategy = (id, strategyData) => {
    return apiClient.put(`/api/strategies/${id}`, strategyData);
};

// --- Approval Workflow Endpoints ---

export const submitForReview = (id) => {
    return apiClient.post(`/api/strategies/${id}/submit`);
};

export const approveStrategy = (id) => {
    return apiClient.post(`/api/strategies/${id}/approve`);
};

export const rejectStrategy = (id, reason) => {
    return apiClient.post(`/api/strategies/${id}/reject`, { reason });
};

export const getStrategiesForReview = () => {
    return apiClient.get('/api/strategies/review-queue');
};

// --- Backtest & Adjustment Endpoints ---

export const runBacktest = (id, backtestRequest) => {
    return apiClient.post(`/api/strategies/${id}/backtest`, backtestRequest);
};

export const performManualAdjustment = (id, adjustmentRequest) => {
    return apiClient.post(`/api/strategies/${id}/adjustments`, adjustmentRequest);
};

export const getAdjustmentHistory = (id) => {
    return apiClient.get(`/api/strategies/${id}/adjustments`);
};

// --- 获取策略实时数据的接口 ---

/**
 * 获取今日成交额 (换手率)
 * @param {number} id 策略ID
 */
export const getTodayTurnoverRate = (id) => {
    return apiClient.get(`/api/strategies/${id}/today-turnover-rate`);
};

/**
 * 获取今日收益
 * @param {number} id 策略ID
 */
export const getTodayProfit = (id) => {
    return apiClient.get(`/api/strategies/${id}/today-profit`);
};

/**
 * 获取累计收益
 * @param {number} id 策略ID
 */
export const getCumulativeProfit = (id) => {
    return apiClient.get(`/api/strategies/${id}/cumulative-profit`);
};